package com.electric.flinkcep.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * 真实电力负荷数据模型
 * 对应 true_data 主题的消息格式
 */
public class TrueData implements Serializable {
    
    @JsonProperty("timestamp")
    private String timestamp;
    
    @JsonProperty("load")
    private double load;
    
    @JsonProperty("max_temp")
    private double maxTemp;
    
    @JsonProperty("min_temp")
    private double minTemp;
    
    @JsonProperty("avg_temp")
    private double avgTemp;
    
    @JsonProperty("humidity")
    private double humidity;
    
    @JsonProperty("rainfall")
    private double rainfall;
    
    @JsonProperty("data_source")
    private String dataSource;
    
    @JsonProperty("sequence_id")
    private int sequenceId;
    
    // 默认构造函数
    public TrueData() {
    }
    
    // 全参构造函数
    public TrueData(String timestamp, double load, double maxTemp, double minTemp, 
                   double avgTemp, double humidity, double rainfall, String dataSource, int sequenceId) {
        this.timestamp = timestamp;
        this.load = load;
        this.maxTemp = maxTemp;
        this.minTemp = minTemp;
        this.avgTemp = avgTemp;
        this.humidity = humidity;
        this.rainfall = rainfall;
        this.dataSource = dataSource;
        this.sequenceId = sequenceId;
    }
    
    /**
     * 获取时间戳的毫秒值
     */
    public long getTimestampMillis() {
        try {
            LocalDateTime dateTime = LocalDateTime.parse(timestamp, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
            return dateTime.atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli();
        } catch (Exception e) {
            return System.currentTimeMillis();
        }
    }
    
    // Getter和Setter方法
    public String getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }
    
    public double getLoad() {
        return load;
    }
    
    public void setLoad(double load) {
        this.load = load;
    }
    
    public double getMaxTemp() {
        return maxTemp;
    }
    
    public void setMaxTemp(double maxTemp) {
        this.maxTemp = maxTemp;
    }
    
    public double getMinTemp() {
        return minTemp;
    }
    
    public void setMinTemp(double minTemp) {
        this.minTemp = minTemp;
    }
    
    public double getAvgTemp() {
        return avgTemp;
    }
    
    public void setAvgTemp(double avgTemp) {
        this.avgTemp = avgTemp;
    }
    
    public double getHumidity() {
        return humidity;
    }
    
    public void setHumidity(double humidity) {
        this.humidity = humidity;
    }
    
    public double getRainfall() {
        return rainfall;
    }
    
    public void setRainfall(double rainfall) {
        this.rainfall = rainfall;
    }
    
    public String getDataSource() {
        return dataSource;
    }
    
    public void setDataSource(String dataSource) {
        this.dataSource = dataSource;
    }
    
    public int getSequenceId() {
        return sequenceId;
    }
    
    public void setSequenceId(int sequenceId) {
        this.sequenceId = sequenceId;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TrueData trueData = (TrueData) o;
        return Double.compare(trueData.load, load) == 0 &&
               sequenceId == trueData.sequenceId &&
               Objects.equals(timestamp, trueData.timestamp);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(timestamp, load, sequenceId);
    }
    
    @Override
    public String toString() {
        return "TrueData{" +
                "timestamp='" + timestamp + '\'' +
                ", load=" + load +
                ", maxTemp=" + maxTemp +
                ", minTemp=" + minTemp +
                ", avgTemp=" + avgTemp +
                ", humidity=" + humidity +
                ", rainfall=" + rainfall +
                ", dataSource='" + dataSource + '\'' +
                ", sequenceId=" + sequenceId +
                '}';
    }
}